package com.apabi.web.controller.api;

import com.apabi.service.JournalService;
import com.apabi.service.elastic.APICode;
import com.apabi.service.elastic.APIResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by teng on 2018/1/16.
 */
@Controller
@RequestMapping("/api/base")
public class BaseController {

    @Autowired
    private JournalService journalService;

    /**
     * 期刊元数据获取
     * @param issn
     * @return
     */
    @RequestMapping(value = "/journal/{code}",method = RequestMethod.GET)
    public @ResponseBody
    APIResult journal(@PathVariable String issn) {
        Map<String, String> map = journalService.selectJournal(issn);
        return new APIResult(APICode.SUCCESS,map);
    }

    /**
     * 学者数据获取
     * @param code
     * @return
     */
    @RequestMapping(value = "/scholar/{code}",method = RequestMethod.GET)
    public @ResponseBody APIResult scholar(@PathVariable String code) {
        Map<String, String> map = journalService.selectScholar(code);
        return new APIResult(APICode.SUCCESS,map);
    }

    /**
     * 机构数据获取
     * @param code
     * @return
     */
    @RequestMapping(value = "/organization/{code}",method = RequestMethod.GET)
    public @ResponseBody APIResult organization(@PathVariable String code) {
        Map<String, String> map = journalService.selectOrganization(code);
        return new APIResult(APICode.SUCCESS,map);
    }

    /**
     * 机构下学者获取
     * @param code
     * @return
     */
    @RequestMapping(value = "/organization/{code}/scholars",method = RequestMethod.GET)
    public @ResponseBody APIResult organizationScholars(@PathVariable String code) {
        List<Map<String, String>> list = journalService.selectOrganizationScholars(code);
        return new APIResult(APICode.SUCCESS,list);
    }
}
